package com.apestech.framework.exec;

import com.apestech.framework.db.SqlSession;
import com.apestech.framework.xml.table.modul.Tables;

/**
 * @author hup
 * @create 2018-12-29-16:04
 */
public class MasterTableExec {

    private Tables table;
    private SqlSession session;
    public MasterTableExec(Tables table, SqlSession session) throws Exception {
        if(table==null) throw new Exception("请检查代码逻辑，表数据不允许为空！");
        this.table=table;
        this.session=session;
    }

    public String getMasterTableDataStr() throws Exception {
        String sql="";
        MasterTableData tabledata=null;
        if(table.isSingleTable()){
            tabledata=new MasterTableData(table.getFirstTable(), table, session);
        } else {
            tabledata=new MasterTableData(table.getMasterTable(), table, session);
        }
        tabledata.setTab(table.getMaster().getTable());
        tabledata.getDataStr();
        if(tabledata.getSql()!=null) return "{"+tabledata.getSql()+"}";
        return null;
    }

    public void getDataXml() throws Exception {
        String sql="";
        MasterTableData tabledata=null;
        if(table.isSingleTable()){
            tabledata=new MasterTableData(table.getFirstTable(), table, session);
        } else {
            tabledata=new MasterTableData(table.getMasterTable(), table, session);
        }
        tabledata.setTab(table.getMaster().getTable());
        tabledata.getDataXml();
    }

}
